package com.droidathletics.boundary.sportsman;

import com.droidathletics.R;
import com.droidathletics.boundary.MainMenu;
import com.droidathletics.control.ManageSportsman;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class CreateSportsman extends Activity {
	private Button saveButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.createsportsman);
        Bundle b = getIntent().getExtras();
        
        manageSportsman = MainMenu.manageSportsman;
        
        name = (EditText) findViewById(R.id.fieldName);
        lastName = (EditText) findViewById(R.id.fieldLastName);
        height = (EditText) findViewById(R.id.fieldHeight);
        weight = (EditText) findViewById(R.id.fieldWeight);
        phoneNumber = (EditText) findViewById(R.id.fieldPhone);
        
        errorData = (TextView) findViewById(R.id.textViewError);
        
        saveButton = (Button) findViewById(R.id.createSSave);
        
        saveButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	String errorResult = manageSportsman.createSporstman("0", 
            			(String)name.getText().toString(), (String)lastName.getText().toString(), 
            			(String)height.getText().toString(), (String)weight.getText().toString(), 
            			(String)phoneNumber.getText().toString());
            	
            	if ( errorResult == "")
            	{
            		finish();
                	Intent intent = new Intent(CreateSportsman.this, MainMenu.class);
                	//MainMenu.addDrawable();
                    startActivity(intent);
            	}
            	else
            	{
            		errorData.setText(errorResult);
            	}

            }
        });        
	}
	
	@Override
    public void onBackPressed() {
		finish();
        Intent intent = new Intent(CreateSportsman.this, MainMenu.class);
        startActivity(intent);
	    return;
    }
	
	private ManageSportsman manageSportsman;
    private EditText name;
    private EditText lastName;
    private EditText height;
    private EditText weight;
    private EditText phoneNumber;
    private TextView errorData;
}
